import React, { useState, useEffect } from 'react'
import api from '../../../../api'
import HomeHotView from '../HomeHotView'
export default function Index(props) {
    const [hot1List, sethot1List] = useState([]); 
    const [hot2List, sethot2List] = useState([]);
    const [cityName1, setcityName1] = useState('')
    const [cityName2, setcityName2] = useState('')
    useEffect(()=>{
        api.getHomeHot1({
            cityName:props.cityName
        }).then(res=>{
            if(res.data.status===200){
                sethot1List(res.data.result)
                setcityName1(res.data.city)
            }
        })
    },[props.cityName])
    useEffect(()=>{
        api.getHomeHot2({
            cityName:props.cityName
        }).then(res=>{
            if(res.data.status===200){
                sethot2List(res.data.result)
                setcityName2(res.data.city)
            }
        })
    },[props.cityName])
    return (
        <div>
            {
                hot1List.length>0?<HomeHotView data={hot1List} city={cityName1} title='新品推荐-'></HomeHotView>:<div>等待数据加载</div>
            }
             {
                hot2List.length>0?<HomeHotView data={hot2List} city={cityName2} title='热门商品-'></HomeHotView>:<div>等待数据加载</div>
            }
        </div>
    )
}
